package com.example.foo.ftt.dao;

import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.ftt.model.FttProfit;
import com.example.foo.ftt.query.FttProfitQuery;

@org.apache.ibatis.annotations.Mapper
public interface FttProfitDao extends com.example.core.dao.BaseDao<FttProfit, Long> {

	public default PageResult<FttProfit> findFttProfits(FttProfitQuery fttProfitQuery, Pageable pageable) {
		QueryWrapper<FttProfit> queryWrapper = createQueryWithBaseIf(fttProfitQuery);
		//
		if (fttProfitQuery.getFttLevel() != null) {
			queryWrapper.eq("ftt_level", fttProfitQuery.getFttLevel());
		}
		if (fttProfitQuery.getPeriodDay() != null) {
			queryWrapper.eq("period_day", fttProfitQuery.getPeriodDay());
		}
		if (fttProfitQuery.getPeriodDayFrom() != null) {
			queryWrapper.ge("period_day", fttProfitQuery.getPeriodDayFrom());
		}
		if (fttProfitQuery.getPeriodDayTo() != null) {
			queryWrapper.le("period_day", fttProfitQuery.getPeriodDayTo());
		}
		if (fttProfitQuery.getState() != null) {
			queryWrapper.eq("state", fttProfitQuery.getState());
		}
		return findPages(queryWrapper, pageable);
	}

	@Update("UPDATE fttprofit "
			+ "SET "
				+ "total_money = total_money + #{totalMoney}, "
				+ "updated_at = #{updatedAt} "
			+ "WHERE id = #{id}")
	public int updateFttProfitTotalMoneyIncrement(FttProfit fttProfit);

}
